php iterate array

37

foreach ($array as $key => $val) {
    print "$key = $val\n";
}
for ($i = 0; $i < count($array); $i++) {
    echo $array[$i]['filename'];
    echo $array[$i]['filepath'];
}
foreach($array as $item) {
    echo $item['filename'];
    echo $item['filepath'];

    // To know what's in $item
    echo '<pre>'; var_dump($item);
}
foreach($array as $i => $item) {
    echo $array[$i]['filename'];
    echo $array[$i]['filepath'];

    // $array[$i] is same as $item
}

Comments

Submit
0 Comments